<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue组件插槽</title>
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
</head>

<body>
    <div id="Application">
        <my-container>
            这是个例子
        </my-container>
    </div>
    <script>
        const App = Vue.createApp({
        })

        const container2Component = {
            template: `
            <div>
                <slot name="header"></slot>
                <hr/>
                <slot name="main"></slot>
                <hr/>
                <slot name="footer"></slot>
            </div>
            `
        }
        App.component("my-container2", container2Component)

        // 下面的组件中的slot是必不可少的，里面的内容在引用组件中没有指定具体内容时就会显示这个默认的内容
        const containerComponent = {
            template: `
            <div style="border-style:solid;border-color:red; border-width:10px">
                <slot>插槽的默认内容</slot>
            </div>
            `
        }
        App.component("my-container", containerComponent)

        App.mount("#Application") 
    </script>
</body>

</html>